package com.yeban.javase.day16.state.timedwaiting;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/30
 *
 * 计时等待状态 → 锁阻塞状态
 */
public class TimedWaitingAndBlocked {
    static final Object lock = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println("线程1持有锁并睡眠3秒");
                    Thread.sleep(3000); // t1处于TIMED_WAITING
                } catch (InterruptedException e) {}
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (lock) {
                System.out.println("线程2获得锁");
            }
        });

        t1.start();
        try { Thread.sleep(500); } catch (InterruptedException e) {}
        t2.start(); // t2进入BLOCKED状态，等待t1释放锁
    }
}
